package kino.command;

import org.springframework.beans.factory.annotation.Autowired;
import kino.client.KinoClient;
import kino.common.KinoConstant;
import kino.server.KinoServer;

@KinoCommandEnable
public class SelectCommand extends AbstractKinoCommand{
    @Autowired
    private KinoServer kinoServer;
    @Override
    public String doExecute(KinoClient client, String... argv) {
        if (this.isNumeric(argv[0]) && Integer.valueOf(argv[0])  < kinoServer.getDbNum()) {
            client.setDb(kinoServer.getDbByNo(Integer.valueOf(argv[0])));
            return KinoConstant.OK;
        }
        return KinoConstant.KEY_DATABASE_NO_ERR;
    }

    @Override
    public Integer getArgc() {
        return 1;
    }

    @Override
    public String getCommandName() {
        return "select";
    }

    @Override
    public boolean aofFlag() {
        return false;
    }

    @Override
    public boolean hasExtParam() {
        return false;
    }

}
